package chen.web.forum;

import java.text.NumberFormat;
import java.util.Date;

import chen.web.user.Account;

public class ForumAccount {

	private Account account;	//帐号
	private int replyCount = 0;		//回复数量
	private int subjectCount = 0;	//主题数量
	private int digestCount = 0;	//精华数量
	private int pageView = 0;		//页面浏览量
	private Date lastPostDate = null;	//上次发帖时间
	
	public ForumAccount(Account account){
		this.account = account;
	}
	
	public int getId(){
		return account.getId();
	}
	
	public Account getAccount() {
		return account;
	}
	public int getReplyCount() {
		return replyCount;
	}
	void setReplyCount(int replyCount) {
		this.replyCount = replyCount;
	}
	public int getSubjectCount() {
		return subjectCount;
	}
	void setSubjectCount(int subjectCount) {
		this.subjectCount = subjectCount;
	}
	public int getDigestCount() {
		return digestCount;
	}
	void setDigestCount(int digestCount) {
		this.digestCount = digestCount;
	}

	public int getPageView() {
		return pageView;
	}

	void setPageView(int pageView) {
		this.pageView = pageView;
	}

	public Date getLastPostDate() {
		return lastPostDate;
	}
	
	public float averagePost(){
		Date lastOffline = account.getLastOffline() == null ? new Date() : account.getLastOffline();
		float days = (lastOffline.getTime() - account.getCreated().getTime())/1000/3600/24f;
		float average = (this.getReplyCount()+this.getReplyCount())/days;
		return average;
	}

	void setLastPostDate(Date lastPostDate) {
		this.lastPostDate = lastPostDate;
	}
	
	synchronized void changeReplyCount(boolean increase){
		if(increase)
			++ this.replyCount;
		else
			-- this.replyCount;
	}
	
	synchronized void changeSubjectCount(boolean increase){
		if(increase)
			++ this.subjectCount;
		else
			-- this.subjectCount;
	}
	
	synchronized void increasePageView(){
		++ this.pageView;
	}	

	synchronized void changeDigestCount(boolean increase){
		if(increase)
			++ this.digestCount;
		else
			-- this.digestCount;
	}
}
